<template>
  <el-main>
    <el-card shadow="never">
      <el-tabs tab-position="top">
        <template v-for="(item, tab) in list" :key="tab">
          <el-tab-pane
            :label="item.config_tab_name"
            v-if="item.config_tab_type == 'kv'"
          >
            <el-form
              ref="form"
              :model="tab"
              label-width="100px"
              style="margin-top: 20px"
            >
              <el-form-item
                v-for="(info, k) in item.list"
                :key="k"
                :label="info.config_key_name"
              >
                <el-input
                  v-model="info.config_value"
                  v-if="info.config_value_type == 'input'"
                ></el-input>
                <el-input
                  v-else-if="info.config_value_type == 'textarea'"
                  type="textarea"
                  :autosize="{ minRows: 4 }"
                  v-model="info.config_value"
                ></el-input>
                <el-switch
                  v-else-if="info.config_value_type == 'switch'"
                  v-model="info.config_value"
                  active-value="1"
                  inactive-value="-1"
                ></el-switch>
                <div class="el-form-item-msg" v-if="info.config_tips != ''">
                  {{ info.config_tips }}
                </div>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="submit(item)">保存</el-button>
              </el-form-item>
            </el-form>
          </el-tab-pane>
        </template>
      </el-tabs>
    </el-card>
  </el-main>
</template>

<script>
export default {
  name: "system",
  data() {
    return {
      list: {},
    };
  },
  mounted() {
    this.getCfg();
  },
  methods: {
    //获取列表
    async getCfg() {
      var res = await this.$API.system.cfg.list.get();
      this.list = res.data;
    },
    async submit(data) {
      var res = await this.$API.system.cfg.save.post(data);
      if (res.code == 200) {
        this.$message.success("操作成功");
      } else {
        this.$alert(res.message, "提示", { type: "error" });
      }
    },
  },
};
</script>

<style>
</style>
